Ext.namespace('Divo');
Ext.namespace('Divo.app');

Divo.app.SupplierAppForm = Ext.extend(Divo.Base.EditForm, {
  fields : new Ext.util.MixedCollection(),
  dataRecordMeta : Ext.data.Record.create([{
        name : "_p_record_status",
        type : "string"
      }, {
        name : "id",
        type : "float"
      }, {
        name : "supplierId",
        type : "float"
      }, {
        name : "supplier",
        type : "string"
      }, {
        name : "typeCode",
        type : "string"
      }, {
        name : "type",
        type : "string"
      }, {
        name : "applicationNote",
        type : "string"
      }, {
        name : "demotion",
        type : "string"
      }]),
  initComponent : function() {
    var me = this;
    var tn = 1;

    this.fields.add("_p_record_status", new Ext.form.Hidden({
              name : "_p_record_status"
            }));
    this.fields.add("id", new Ext.form.Hidden({
              name : "id",
              dataIndex : "id",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("supplierId", new Ext.form.Hidden({
              name : "supplierId",
              dataIndex : "supplierId",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("demotion", new Ext.form.Hidden({
              name : "demotion",
              dataIndex : "demotion",
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("supplier", new app.base.ComboBox({
              fieldLabel : '选择供应商',
              name : 'supplier',
              tabIndex : tn++,
              store : Divo.com.Lib.getSupplierBlackDs(),
              displayField : 'name',
              dataIndex : 'supplier',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 300,
              labelSeparator : ":*",
              width : 150,
              minChars : 0,
              allowBlank : false,
              tpl : resultTpl,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("supplier", data.name);
                this.onTriggerClick();
              }
            }));
    this.fields.add("applicationNote", new app.base.TextArea({
              name : "applicationNote",
              dataIndex : "applicationNote",
              fieldLabel : "申请原因",
              allowBlank : false,
              labelSeparator : ":*",
              tabIndex : tn++,
              width : 150,
              insert_allowed : true,
              update_allowed : true
            }));
    this.fields.add("typeCodeG", new Ext.form.RadioGroup({
          name : "typeCodeG",
          dataIndex : "typeCodeG",
          fieldLabel : "动作名称",
          allowBlank : false,
          labelSeparator : ":*",
          tabIndex : tn++,
          width : 170,
          defaultType : 'radio',
          items : [{
                fieldLabel : '',
                boxLabel : '升降级',
                name : 'typeCode',
                inputValue : '1',
                listeners : {
                  check : function() {
                    if (null != me.getField("typeCodeG").getValue()) {
                      if (me.getField("typeCodeG").getValue().inputValue == "1") {
                        me.getField("typeG").setVisible(true);
                        me.getField("typeG").allowBlank = false;
                      }

                      if (me.getField("typeCodeG").getValue().inputValue == "2") {
                        me.getField("typeG").setVisible(false);
                        me.getField("typeG").allowBlank = true;
                      }
                    }
                  }
                }
              }, {
                checked : true,
                fieldLabel : '',
                labelSeparator : '',
                boxLabel : '调出黑名单',
                name : 'typeCode',
                inputValue : '2'
              }],
          insert_allowed : true,
          update_allowed : true
        }));
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "code",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }]);
    var storeDs = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'supplier/query_type'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    var t1 = '<tpl for=\".\">';
    var t2 = '</tpl>';
    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{code}--{name}</b><br>', '</div>' + t2].join('');
    this.fields.add("typeG", new app.base.ComboBox({
              fieldLabel : '选择类型',
              name : 'typeG',
              tabIndex : tn++,
              store : storeDs,
              displayField : 'code',
              dataIndex : 'typeG',
              mode : 'remote',
              typeAhead : false,
              forceSelection : true,
              loadingText : '正在搜索...',
              listWidth : 300,
              labelSeparator : ":*",
              width : 150,
              minChars : 0,
              allowBlank : true,
              tpl : resultTpl,
              insert_allowed : true,
              update_allowed : true,
              onSelect : function(record) {
                var data = record.data;
                me.setFieldValue("typeG", data.code);
                me.setFieldValue("demotion", data.code);
                this.onTriggerClick();
              }
            }));
    Ext.apply(this, {
          items : [this.fields.get("_p_record_status"), {
            layout : "form",
            columnWidth : 1,
            labelAlign : "right",
            labelWidth : 100,
            items : [this.fields.get("id"), this.fields.get("supplierId"),
                this.fields.get("demotion"), this.fields.get("supplier"),
                this.fields.get("applicationNote"),
                this.fields.get("typeCodeG"), this.fields.get("typeG")]
          }],
          border : false,
          frame : true,
          firstFocusFieldName : "supplier"
        });

    Divo.app.SupplierAppForm.superclass.initComponent.apply(this, arguments);
  }

  ,
  onRender : function() {
    Divo.app.SupplierAppForm.superclass.onRender.apply(this, arguments);
  },
  newDataRecord : function() {
    return new this.dataRecordMeta({
          _p_record_status : "insert",
          id : "",
          name : "",
          state : ""
        });
  }

});
Ext.reg("Divo.app.SupplierAppForm", Divo.app.SupplierAppForm);